1 using UnityEngine;
2 using
System.Collections;
3
4 public
class VehicleCollision : MonoBehaviour {
5
6     
public AudioSource audioSource;
7     
public AudioClip clip;
8     
// Use this for initialization
9     
void Start () {
10         audioSource = GetComponent<AudioSource> ();
11     
12     }
13     
14     
// Update is called once per frame
15     
void Update () {
16     
17     }
18
19     
void OnTriggerEnter(Collider other){
20         
if (other.gameObject.tag == "Player") {
21             PlayerHealth playerHealth = other.gameObject.GetComponent<PlayerHealth>();
22             playerHealth.Death ();
23             audioSource.PlayOneShot (clip);
24         }
else if (other.gameObject.tag == "Enemy") {
25             EnemyHealth enemyHealth = other.gameObject.GetComponent<EnemyHealth> ();
26             enemyHealth.Death ();
27             audioSource.PlayOneShot (clip);
28
29         }
30     }
31 }


Gõ tìm kiếm nhanh...